home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 52
/
Amiga Format AFCD52 (Issue 136, May 2000).iso
/
-serious-
/
programming
/
basic
/
mildred
/
mildred.lha
/
lha
/
GravityExample.lha
/
GravityExample.ascii
next >
Wrap
Text File
|
1999-03-03
|
11KB
|
326 lines
WBStartup
NoCli
; Map files full path
map$="data/map.lmap"
#vwidth=320 ; ViewWidth
#vwidth2=#vwidth/2 ; Half ViewWidth
#vheight=256 ; ViewHeight
#vheight2=#vheight/2 ; Half ViewHeight
#bmwidth=#vwidth ; Bitmap Width
#bmheight=#vheight ; Bitmap Height
#numblocks=2 ; How Many Background Blocks we use
#numbul=200 ; number of available bullets
#anglesweep=64 ; Full Circle (have to be power of 2!!!)
#half=#anglesweep/2 ; Half Circle
#quarter=#half/2 ; Quarter Circle
#quarquar=#quarter/2 ; Half Of Qaurter Circle
#BOOL_FALSE=0 ; BOOLEAN FALSE (same as False)
#BOOL_TRUE=1 ; BOOLEAN TRUE (same as True)
slot.w=10 ; slot^2 is the amount of full views in
; our playing arena
degrad.q=Pi/(#anglesweep/2) ; Adding "Angle" by one adds it this many radians
death.w=#BOOL_FALSE ; Are we Dead?
NEWTYPE .ship ; Our Ship
x.q
y.q
velx.q
vely.q
End NEWTYPE
NEWTYPE.pos ; Bullets Position
x.q
y.q
End NEWTYPE
NEWTYPE.vel ; Bullets Velocity
vx.q
vy.q
End NEWTYPE
MReserveBitmaps 1 ; We're going to use 1 chunky bitmap.
MReservec2pWindows 1 ; We only need one c2p display.
; We need shapes for the ship and for background.
; and one for background saving
MReserveShapes #anglesweep+#numblocks+2
.initgraphics
; Here we will allocate our chunky buffer.
dwidth.w=slot*#vwidth
dheight.w=slot*#vheight
cmap.l=MBitmap(0,dwidth,dheight) ; 10*10 times the view so it's huge ;)
If cmap=0 ; If not enough memory we try to get smaller one
slot=slot-2
If slot>0 ; if we have slot value at least 1 we try to get the bitmap
Goto initgraphics
Else
End ; if it goes for null we have only one solution -> to QUIT
EndIf
EndIf
MUseBitmap 0 ; And We use it
; Make some shapes
MBoxF 0,0,15,15,127 ; This is normal Wall
MGetaShape 1,0,0,16,16 ; Grab the shape
MBoxF 0,0,15,5,255 ; And This one is a landing zone
MGetaShape 2,0,0,16,16 ; And Grab it
MBoxF 0,0,15,15,0 ; Clean the area
Dim scx.q(#anglesweep-1,2) ; These are used in collision detecting
Dim scy.q(#anglesweep-1,2) ; Very lame, but enough for example ;)
Dim bx(#anglesweep-1) ; Bullet start x offset
Dim by(#anglesweep-1) ; Bullet start y offset
Dim bvx(#anglesweep-1) ; Bullet X Velocity
Dim bvy(#anglesweep-1) ; bullet Y Velocity
For l.l=0 To #anglesweep-1 ; Make The Ship and fill those collision
; etc arrays
bx(l)=Cos((l+#half)*degrad)*10+7
by(l)=Sin((l+#half)*degrad)*10+7
bvx(l)=Cos((l+#half)*degrad)*4.5
bvy(l)=Sin((l+#half)*degrad)*4.5
x1.q=Cos((l+#half)*degrad)*7+7
y1.q=Sin((l+#half)*degrad)*7+7
x2.q=Cos((l-#quarquar)*degrad)*5+7
y2.q=Sin((l-#quarquar)*degrad)*5+7
x3.q=Cos((l+#quarquar)*degrad)*5+7
y3.q=Sin((l+#quarquar)*degrad)*5+7
scx(l,0)=x1
scy(l,0)=y1
scx(l,1)=x2
scy(l,1)=y2
scx(l,2)=x3
scy(l,2)=y3
MInk 255
MLine x1,y1,x2,y2
MLine x3,y3
MLine x1,y1
MGetaShape l+3,0,0,16,16
MBoxF 0,0,15,15,0
Next l
BitMap 2,200,160,2 ; Initialize our maps bitmap
LoadBitMap 2,map$ ; We need 2 plane one
Use BitMap 2
For l.l=0 To slot*20-1
For t.l=0 To slot*16-1
ll.l=l LSL 4
tt.l=t LSL 4
s.w=Point(l,t)
If s>0
MTile16x16 s,ll,tt ; We build up the scene
Else
MBoxF ll,tt,ll+15,tt+15,0 ; These are the FLY ZONE ;)
EndIf
Next t
Next l
; Setup structures for c2p conversions.
Mc2pWindow 0,#vwidth,#vheight,dwidth,#bmwidth,#bmheight
MUsec2pWindow 0 ; We use this newly created c2p window
Dim bm.l(1) ; We use two bitmaps for double buffering
For l=0 To 1
; Get some free CHIP memory
bm(l)=AllocMem(#bmwidth*#bmheight,#MEMF_CHIP)
If bm(l) ; and if we succeed
; make it a planar bitmap.
CludgeBitMap l,#bmwidth,#bmheight,8,bm(l)
Else
End
EndIf
Next l
; We need screen too ;)
Dim scrtaglst.TagItem(7) ; All this stuff sets up our
scrtaglst(0)\ti_Tag = #SA_Left ; Taglist for the screen we
scrtaglst(0)\ti_Data = 0 ; want.
scrtaglst(1)\ti_Tag = #SA_Depth
scrtaglst(1)\ti_Data = 8
scrtaglst(2)\ti_Tag = #SA_Width
scrtaglst(2)\ti_Data = #vwidth
scrtaglst(3)\ti_Tag = #SA_Height
scrtaglst(3)\ti_Data = #vheight
scrtaglst(4)\ti_Tag = #SA_BitMap
scrtaglst(4)\ti_Data = Addr BitMap (0)
scrtaglst(5)\ti_Tag = #SA_ShowTitle
scrtaglst(5)\ti_Data = 0
scrtaglst(6)\ti_Tag = #SA_Draggable
scrtaglst(6)\ti_Data = 0
scrtaglst(7)\ti_Tag = #TAG_END ; The most important tag of them all.
ScreenTags 0,"MildredDEMO",&scrtaglst(0) ; Open our intuition screen.
InitPalette 0,255 ; Initialize GrayScalePalette
For l.l=0 To 255
AGAPalRGB 0,l,l,l,l
Next l
ShowPalette 0 ; Attach our palette to the screen.
Dim thrustx.q(#anglesweep-1),thrusty.q(#anglesweep-1)
; These are used in acceleration
; Precalculated tables are much faster than using sine and cosine functions
For t.l=0 To #anglesweep-1
thrustx(t)=-Cos(degrad*t)*0.00027
thrusty(t)=-Sin(degrad*t)*0.00027
Next t
shp.ship\x=#vwidth2,#vheight2 ; Init start position of our ship
shp.ship\velx=0.0,0.0
angle.w=#quarter ; and the start angle
x.q=0 ; Temporary Coordinate variables
y.q=0
act.w=0 ; active bitmap number
fuel.l=4000 ; Amount of fuel we have
mass.l=8000-fuel ; And our Mass is here (it is reverse)
; The higher it is the faster the ship will move
MGetaShape #anglesweep+3,x,y,16,16 ; save background of the ship
Dim bpos.pos(#numbul-1),bvel.vel(#numbul-1)
Dim bul.w(#numbul-1),bg.vel(#numbul-1)
; Init Bullet variables here
For l=0 To #numbul-1
bpos(l)\x=0,0
bvel(l)\vx=0,0
bul(l)=0
bg(l)\vx=0,0.045
Next l
MParticleFormat -1 ; Data is in x.q,y.q format
; Main Loop starts here!
Repeat
xx.l=Min(Max(0,shp\x-#vwidth2),dwidth-#vwidth) ; Super Bitmap X position
yy.l=Min(Max(0,shp\y-#vheight2),dheight-#vheight) ; Super Bitmap Y position
Mc2p 0,MBitmapPtr(xx,yy,0),bm(act) ; Make C2P to the bitmap
; For GFX Board version
; this have to be replaced with something like writepixelarray_
WaitTOF_ ; Wait top of frame and...
ShowBitMap act ; show the next frame
MBoxF x,y,x+15,y+15,0 ; Clear the ship area
MBlit #anglesweep+3,x,y ; And restore background
act=1-act ; Swap active bitmap
cangle.w=angle ; Collision angle (if collision detected
; angle=cangle)
ax.w=Joyx(1) ; read Joy
angle=(angle+ax)&(#anglesweep-1) ; and calculate new angle
x=shp\x ; Init Temporary coordinates
y=shp\y
If Joyb(1)=1 AND fuel>0 ; Are we thrusting and do we have fuel?
fuel-1 ; Sub fuel
mass+1 ; and add mass -> will thrust more
accx.q=(thrustx(angle)*mass) ; X Acceleration
accy.q=(thrusty(angle)*mass)+0.35 ; Y Acceleration
shp\velx+accx-(shp\velx*0.02) ; X Velocity
shp\vely+accy-(shp\vely*0.02) ; Y Velocity
Else
shp\velx-(shp\velx*0.02) ; X Velocity
shp\vely+(0.35-(shp\vely*0.02)) ; Y Velocity
EndIf
x+shp\velx ; Add Velocity to Temp Coordinates
y+shp\vely
sx1.w=x+scx(angle,0) ; Collision coordinates
sy1.w=y+scy(angle,0)
sx2.w=x+scx(angle,1)
sy2.w=y+scy(angle,1)
sx3.w=x+scx(angle,2)
sy3.w=y+scy(angle,2)
mp1.w=MPoint(sx1,sy1)&$ff ; Read Collision point colours
mp2.w=MPoint(sx2,sy2)&$ff
mp3.w=MPoint(sx3,sy3)&$ff
scol.w=0 ; Collisions hapened
slnd.w=0 ; Landing points true
If mp1>0 ; If the first collision point is larger than 0 then
scol+1 ; collision true for this point
EndIf
If mp2>0 ; If second point is larger than 0 we check
If mp2=255 ; if the colour is 255
slnd+1 ; it is so Landing in point 1 is true
EndIf
scol+2 ; and collision is also true
EndIf
If mp3>0 ; If third point is larger than 0 we check
If mp3=255 ; if the colour is 255
slnd+2 ; it is so Landing in point 1 is true
EndIf
scol+4 ; and collision is also true
EndIf
If slnd=3 AND sy2=sy3 ; If both landing points are true we do landing
If shp\vely<0.36 AND shp\vely>0
shp\vely=0 : y=shp\y : shp\velx=0
Else
shp\vely=shp\vely*(0.85*Sgn(-shp\vely))
shp\velx=shp\velx*0.85
EndIf
scol-6 ; And these points can't collide any more
EndIf
If scol>0 ; Is any collisions?
If scol=7 Then death=#BOOL_TRUE ; If all points collide we are DEAD!!!
shp\velx=-shp\velx*0.3 ; Else Our velocity will drop and reverse
shp\vely=-shp\vely*0.3 ; ie we bounce
x=shp\x ; and our position is not coing to change
y=shp\y
angle=cangle ; and angle is restored
EndIf
shp\x=x ; Put temp position to ship
shp\y=y
For l=0 To #numbul-1 ; Wipe off all bullets which are
If bul(l)>0 ; currently wisible
bul(l)-1 ; and sub it's life
MPlot bpos(l)\x,bpos(l)\y,0 ; and restore background colour 0
EndIf
Next l
If shootdelay.w>0 Then shootdelay-1 ; If we have shot then we have to wait a litle
If Joyy(1)=-1 AND shootdelay.w=0 ; Are we Shooting?
shootdelay.w=0 ; Set delay so that shooting is slower
curbul+1 ; Add current bullet by one
If curbul=#numbul Then curbul=0 ; We chenck if we need to start from the first one
bul(curbul)=400 ; Bullets life in frames
bpos(curbul)\x=x+bx(angle),y+by(angle) ; It's position
bvel(curbul)\vx=bvx(angle),bvy(angle) ; and velocity
EndIf
MAddToParticles &bvel(0)\vx,#numbul,&bg(0)\vx ; make gravity changes to bullets velocities
MAddToParticles &bpos(0)\x,#numbul,&bvel(0)\vx ; add velocity to coords
For l=0 To #numbul-1 ; draw active bullets
If bul(l)>0
bc.w=MPoint(bpos(l)\x,bpos(l)\y)&$ff
If bc=0 OR bc=255
MPlot bpos(l)\x,bpos(l)\y,255
Else
bul(l)=0
EndIf
EndIf
Next l
MGetaShape #anglesweep+3,x,y,16,16 ; save background
MBlit angle+3,x,y ; and blit the ship
Until RawStatus($45) OR death ; until we "escape" or death
End ; End our nice program.;)